package com.service.schedule.sys;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.model.Global;
import com.dao.sys.UserDao;
import com.model.sys.UserModel;
import com.service.external.oa.HrService;

import localhost.services.hrmservice.HrmServiceStub.UserBean;

@Service("SysOaScheduleService")
public class SysOaScheduleService {
	static final Logger logger = LoggerFactory.getLogger(SysOaScheduleService.class);

	@Autowired
	HrService hrService;
	@Autowired
	UserDao userDao;

	public void getOaId() {
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("DISABLED", "1");
//		hashMap.put("USERID", "9fb8c2eb-6393-4580-ada2-dabf21ce0afc");
		List<UserModel> userModels = userDao.selectList(hashMap);
		int i = 0;
		for (UserModel userModel : userModels) {
			if (com.common.StringUtils.isNullOrEmpty(userModel.getWX())) {
				continue;
			}
			UserBean userBean = hrService.getHrmUserInfo(userModel.getWX());
			if (userBean != null) {
				if (userBean.getStatus().equals("5") || userBean.getStatus().equals("4")) {
					// 禁用
					System.out.println("userbean:" + userBean.getStatus());
					userModel.setDISABLED(Global.NO + "");
				} else {
					// 启用
					userModel.setDISABLED(Global.YES + "");
					userModel.setOa(userBean.getUserid() + "");
					userModel.setOaDeptId(userBean.getDepartmentid());
					userModel.setOaDeptName(userBean.getDepartmentname());
					userModel.setCASID(userBean.getLoginid());
				}
			} else {
				// 禁用
				userModel.setDISABLED(Global.NO + "");
			}
			userDao.update(userModel);
		}
	}
}
